﻿using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.EKA.MVCExtensions;
using Wicresoft.EKA.ITSM.Business;

namespace Wicresoft.EKA.ITSM.Web.WebPortal.Controllers
{
    public class ExampleController : BaseController
    {
        [Inject]
        public ICTMPeople CTMPeople { get; set; }

        [Inject]
        public IUser UserI { get; set; }

        [Inject]
        public override IUserInfo UserInfo { get; set; }  //每个Controller必须包含的。

        protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            ((IBase)CTMPeople).UserIdentify = UserName;
            ((IBase)UserI).UserIdentify = UserName;

            base.OnActionExecuting(filterContext);
        }

        protected override void Dispose(bool disposing)
        {
            ((IDisposable)CTMPeople).Dispose();
            ((IDisposable)UserI).Dispose();
        }

        //
        // GET: /Example/
        [Permission(Roles="Group,")]
        public ActionResult Index()
        {
            ViewBag.Peoples = UserI.GetUserByLoginID(UserName);
            return View();
        }

        //
        // GET: /Example/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Example/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Example/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Example/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Example/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Example/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Example/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
